/**
 * 版权所有（c）2021. 上海海鼎信息工程股份有限公司，保留所有权利
 */
package com.lovely602.design.structure.proxy.dynamic.demo;


import com.lovely602.design.structure.proxy.dynamic.ProxyHandler;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 * @author lizhixing
 */
public class ProxyHandlerTest {

  public static void main(String[] args) {
    System.getProperties().setProperty("sun.misc.ProxyGenerator.saveGeneratedFiles", "true");

    HelloInterface hello = new Hello();
    InvocationHandler helloHandler = new ProxyHandler(hello);
    HelloInterface proxyHello = (HelloInterface) Proxy.newProxyInstance(hello.getClass().getClassLoader(), hello.getClass().getInterfaces(), helloHandler);
    proxyHello.sayHello();

    ByeInterface bye = new Bye();
    InvocationHandler byeHandler = new ProxyHandler(bye);
    ByeInterface proxyBye = (ByeInterface) Proxy.newProxyInstance(bye.getClass().getClassLoader(), bye.getClass().getInterfaces(), byeHandler);
    proxyBye.sayBye();
  }
}
